package yeh.dao;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import yeh.domain.LoginLog;
import yeh.domain.User;

import java.util.Date;
import java.util.List;

@Repository
public interface UserDao {
    /**
     * Dao层查询用户名和密码
     * @param UserName
     * @param PassWord
     * @return
     */
    @ResultMap("UserResultMap")
    @Select("select user_name, pass_word from tb_user where user_name=#{UserName} and pass_word=#{PassWord}")
    User SelectAll(@Param("UserName") String UserName, @Param("PassWord") String PassWord);

    /**
     * Dao层保存登录日志信息到日志表中
     */
    @Insert("INSERT INTO login_info(username,ip,login_time) VALUES(#{username},#{ip},#{loginTime})")
    void saveLoginLog(@Param("username") String username, @Param("ip") String ip,@Param("loginTime") Date loginTime);

    /**
     * Dao层读取登录日志
     */
    @ResultMap("LoginlogResultMap")
    @Select("SELECT username, ip, login_time from login_info")
    List<LoginLog> getLoginLogs();
}
